package org.carry.god.module.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.carry.god.module.system.api.user.UserRespDTO;
import org.carry.god.module.system.controller.user.vo.UserSaveReqVO;
import org.carry.god.module.system.domain.UserDO;
import org.carry.god.module.system.mapper.UserMapper;
import org.carry.god.module.system.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author wanglei
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long createUser(UserSaveReqVO userSaveReqVO) {
        UserDO bean = BeanUtil.toBean(userSaveReqVO, UserDO.class);
        userMapper.insert(bean);
        return bean.getId();
    }

    @Override
    public UserRespDTO getUserByUsername(String username) {
        UserDO user = userMapper.selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getUsername, username));
        return BeanUtil.toBean(user, UserRespDTO.class);
    }
}
